<template>
  <div class="login" :style="bacpic">
    <div class="box">
      <div class="title">用户登录</div>
      <div class="ipt">
        <input type="text" placeholder="用户名" />
      </div>
      <div class="ipt">
        <input type="password" placeholder="密码" />
      </div>
      <div class="yanzheng">
        <div class="ipt">
          <input type="text" placeholder="验证码" />
        </div>
        <div @click="refreshCode">
          <SIdentify :identifyCode="identifyCode" />
        </div>
      </div>
      <div class="text">
        <span @click="goRegister">去注册</span>
        <span>忘记密码？</span>
      </div>
      <div class="btn">
        <input type="button" value="登录" />
      </div>
    </div>
  </div>
</template>

<script setup>
import SIdentify from "../components/SIdentify.vue";
import { ref, onMounted } from "vue";
import bac from "../assets/bac.png";
import { useRouter } from "vue-router";
var $router = useRouter();

var bacpic = ref({
  backgroundImage: "url(" + bac + ")",
  backgroundRepeat: "no-repeat",
  backgroundSize: "cover",
  minHeight: "100vh",
  position: "relative",
  backgroundPosition: "center center",
});
var goRegister = () => {
  $router.push("/register");
};

//验证码
// 图形验证码
let identifyCodes = "1234567890";
let identifyCode = ref("3212");
const randomNum = (min, max) => {
  return Math.floor(Math.random() * (max - min) + min);
};

const makeCode = (o, l) => {
  for (let i = 0; i < l; i++) {
    identifyCode.value += o[randomNum(0, o.length)];
  }
};

const refreshCode = () => {
  identifyCode.value = "";
  makeCode(identifyCodes, 4);
};

onMounted(() => {
  identifyCode.value = "";
  makeCode(identifyCodes, 4);
});
</script>

<style scoped lang="scss">
.login {
  overflow: hidden;
  .box {
    width: 300px;
    margin: 200px auto;
    background-color: white;
    padding: 20px 40px 20px;
    .title {
      line-height: 30px;
    }
    .ipt {
      line-height: 40px;
      input {
        width: 100%;
        height: 30px;
        border: 1px solid #ccc;
        outline: none;
        border-radius: 5px;
        padding-left: 5px;
        color: #ccc;
        font-size: 12px;
      }
    }
    .yanzheng{
      display: flex;
      justify-content: space-between;
    }
    .text {
      line-height: 25px;
      display: flex;
      justify-content: space-between;
      font-size: 12px;
      color: lightskyblue;
      cursor: pointer;
    }
    .btn {
      margin: 30px auto;
      padding: 0 98px;
      input {
        padding: 5px 40px;
        border: none;
        background-color: rgb(55, 158, 243);
        border-radius: 40px;
        color: white;
        font-size: 12px;
        cursor: pointer;
      }
    }
  }
}
</style>